package com.warm.demo.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.warm.core.domain.R;
import com.warm.core.page.BaseController;
import com.warm.demo.api.dto.TestTreeDto;
import com.warm.demo.api.vo.TestTreeVo;
import com.warm.demo.service.ITestTreeService;
import com.warm.log.annotation.Log;
import com.warm.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.noear.solon.annotation.*;
import org.noear.solon.validation.annotation.Valid;

import java.util.List;

/**
 * 测试树Controller
 *
 * @author warm
 */
@Api(value = "测试树控制器", tags = {"测试树管理"})
@Valid
@Controller
@Mapping("/test/tree")
public class TestTreeController extends BaseController {
    @Inject
    private ITestTreeService testTreeService;

    /**
     * 分页查询测试树列表
     */
    @ApiOperation("分页查询测试树列表")
    @SaCheckPermission("test:tree:list")
    @Get
    @Mapping("/list")
    public R<List<TestTreeVo>> list(TestTreeDto dto) {
        return R.ok(testTreeService.selectList(dto));
    }


    /**
     * 获取测试树详细信息
     */
    @ApiOperation("获取测试树详细信息")
    @SaCheckPermission("test:tree:query")
    @Get
    @Mapping(value = "/{id}")
    public R<TestTreeVo> getInfo(Long id) {
        return R.ok(testTreeService.selectById(id));
    }

    /**
     * 新增测试树
     */
    @ApiOperation("新增测试树")
    @SaCheckPermission("test:tree:add")
    @Log(title = "测试树", businessType = BusinessType.INSERT)
    @Post
    @Mapping
    public R<Void> add(TestTreeDto dto) {
        return toR(testTreeService.insertByDto(dto));
    }

    /**
     * 修改测试树
     */
    @ApiOperation("修改测试树")
    @SaCheckPermission("test:tree:edit")
    @Log(title = "测试树", businessType = BusinessType.UPDATE)
    @Put
    @Mapping
    public R<Void> edit(TestTreeDto dto) {
        return toR(testTreeService.updateByDto(dto));
    }

    /**
     * 删除测试树
     */
    @ApiOperation("删除测试树")
    @SaCheckPermission("test:tree:remove")
    @Log(title = "测试树", businessType = BusinessType.DELETE)
    @Delete
    @Mapping("/{ids}")
    public R<Void> remove(Long[] ids) {
        return toR(testTreeService.deleteByIds(ids));
    }
}
